package hyrpt

class ProcessInventoryController {

    def dynamicQueryService

    def processInventory() {
        def pageCurrent = params.pageCurrent ? Integer.parseInt(params.pageCurrent) : 1
        def pageSize = params.pageSize ? Integer.parseInt(params.pageSize) : 100
        params.startno = (pageSize * (pageCurrent - 1)) + 1
        params.endno = pageSize * pageCurrent
        def tableHeadList = []
        def processInventory = []
        def pageSizeList = [10, 20, 50, 100]
        def totalCount = 0
        def processInventorySumQty = []
        params.SYS_QUERY_NAME = 'wipStateList'
        def wipStateList = dynamicQueryService.queryForList(params)
        if (params.EXPORT_CONTENT_NAME == 'Excel') {
            params.SYS_QUERY_NAME = 'processInventory'
            processInventory = dynamicQueryService.queryForList(params)
            if (processInventory.size() > 0) {
                tableHeadList = processInventory[0].keySet()
            }
            params.SYS_QUERY_NAME = 'processInventoryCount'
            totalCount = dynamicQueryService.queryForList(params)[0].TOTALCOUNT
            params.SYS_QUERY_NAME = 'processInventorySumQty'
            processInventorySumQty = dynamicQueryService.queryForList(params)
        }
        [
                startno               : params.startno ?: '',
                endno                 : params.endno ?: '',
                pageSize              : pageSize,
                totalCount            : totalCount,
                pageSizeList          : pageSizeList,
                tableHeadList         : tableHeadList,
                processInventory      : processInventory,
                processInventorySumQty: processInventorySumQty,
                wipStateList          : wipStateList,
                lotId                 : params.lotId ?: '',
                startTime             : params.startTime ?: '',
                endTime               : params.endTime ?: '',
                lineId                : params.lineId ?: '',
                partName              : params.partName ?: '',
                zt                    : params.zt ?: '',
                stepDesc              : params.stepDesc ?: '',
                stepName              : params.stepName ?: ''
        ]
    }
}